# create an array of arrays (ragged_array)
Random.seed!(94);
n = 101
beta_seq = collect(range(0,1,length=n));
H = rand(Uniform(130, 170), 1);
W = sim_weight(H, 0.5, 10);
# initialize empty arrays
HH = []
WW = []
# add first observation to HH and WW
push!(HH, H)
push!(WW, W)
for j in 2:n
H_new = rand(Uniform(130,170), 1)
W_new = sim_weight( H_new , 0.5 , 10 )
push!(HH, vcat(HH[j-1],H_new))
push!(WW, vcat(WW[j-1],W_new))
end
# recompute posterior
PP = [ vec(compute_post(WW[i],HH[i],0,beta_seq,10)["post", :]) for i in 1:n ];
# initialize empty plots
plots = Plots.Plot[plot(title="N = $i") for i in 1:n]
for i in 1:n
p = plot(xlim=(130,170), ylim=(50,90),
xlabel="height (cm)", ylabel="weight (kg)",
title=string("N = ", i))
for j in 1:n
slope = beta_seq[j]
lwd = 4*PP[i][j]/maximum(PP[i])
p = Plots.abline!(p, slope, 0, line=:solid, width=lwd, color=:black,
linealpha=.8)
end
plots[i] = scatter!(p, HH[i], WW[i],
markercolor=:white, markersize=4, markeralpha=.8,
markerstrokecolor=:red, markerstrokewidth=2)
end
# plot grid
plot(plots[1], plots[2], plots[3], plots[10], plots[20], plots[89],
layout=(3,2), size = (800,1200))